package cn.dt70.service.impl;

import cn.dt70.dao.aqbCreditor.AqbCreditorMapper;
import cn.dt70.pojo.AqbCreditor;
import cn.dt70.service.AqbCreditorService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class AqbCreditorServiceImpl implements AqbCreditorService {

    private static final Logger LOGGER = Logger.getLogger(AqbCreditorServiceImpl.class);

    @Resource
    private AqbCreditorMapper aqbCreditorMapper;

    @Override
    public List<AqbCreditor> findAllCreditorById(Integer transferStatus) {
        List<AqbCreditor> CreditorList = new ArrayList<>();

        try {
            CreditorList = aqbCreditorMapper.queryAll(transferStatus);
            if(CreditorList.size()<=0){
                LOGGER.debug("债权查询为空");
            }else{
                LOGGER.debug("查询成功！");
            }
        } catch (Exception e) {
            LOGGER.error("查询异常"+e.getMessage());
        }
        return CreditorList;
    }

    @Override
    public List<AqbCreditor> findCreditorById(Integer id,Integer querytime) {
        List<AqbCreditor> CreditorList = new ArrayList<>();

        try {
            CreditorList = aqbCreditorMapper.queryById(id,querytime);
            if(CreditorList.size()<=0){
                LOGGER.debug("债权查询为空");
            }else{
                LOGGER.debug("查询成功！");
            }
        } catch (Exception e) {
            LOGGER.error("查询异常"+e.getMessage());
        }
            return CreditorList;
    }

    @Override
    public List<AqbCreditor> findCreditorDoneById(Integer id, Integer querytime) throws Exception {
        List<AqbCreditor> CreditorList = new ArrayList<>();

        try {
            CreditorList = aqbCreditorMapper.queryDoneById(id,querytime);
            if(CreditorList.size()<=0){
                LOGGER.debug("债权查询为空");
            }else{
                LOGGER.debug("查询成功！");
            }
        } catch (Exception e) {
            LOGGER.error("查询异常"+e.getMessage());
        }
        return CreditorList;
    }

    @Override
    public boolean addCreditor(AqbCreditor aqbCreditor) throws Exception {
            int row = 0;

            try {
                row = aqbCreditorMapper.addCreditor(aqbCreditor);
                if(row!=1){
                    LOGGER.debug("添加债权失败！");
                    return false;
                }else{
                    LOGGER.debug("添加债权成功！");
                    return true;
                }
            } catch (Exception e) {
                LOGGER.error("添加失败"+e.getMessage());
                    return false;
            }
    }

    @Override
    public AqbCreditor findCreditorByCid(Integer cId) throws Exception {

        try {
            if(null!=aqbCreditorMapper.queryCreditorById(cId)){
                LOGGER.debug("债权查询成功!");
            }else{
                LOGGER.debug("债权查询失败！");
            }
        } catch (Exception e) {
            LOGGER.error("债权查询异常！"+e.getMessage());
        }
        return aqbCreditorMapper.queryCreditorById(cId);
    }

    @Override
    public boolean updateCreditorById(AqbCreditor aqbCreditor) throws Exception {
         int row = 0;

        try {
            row = aqbCreditorMapper.updateCreditorById(aqbCreditor);
            if(row!=1){
                LOGGER.debug("承接修改债权失败！");
                return false;
            }else{
                LOGGER.debug("承接修改债权成功！");
                return true;
            }
        } catch (Exception e) {
            LOGGER.error("承接失败"+e.getMessage());
            return false;
        }

    }

    @Override
    public List<AqbCreditor> findCreditorByIdForTime(Integer id, Date begin, Date end) throws Exception {
        List<AqbCreditor> CreditorList = new ArrayList<>();

        try {
            CreditorList = aqbCreditorMapper.queryCreditorByIdForTime(id,begin,end);
            if(CreditorList.size()<=0){
                LOGGER.debug("债权查询为空");
            }else{
                LOGGER.debug("查询成功！");
            }
        } catch (Exception e) {
            LOGGER.error("查询异常"+e.getMessage());
        }
        return CreditorList;
    }

    @Override
    public List<AqbCreditor> findCreditorDoneByIdForTime(Integer id, Date begin, Date end) throws Exception {
        List<AqbCreditor> CreditorList = new ArrayList<>();

        try {
            CreditorList = aqbCreditorMapper.queryCreditorDoneByIdForTime(id,begin,end);
            if(CreditorList.size()<=0){
                LOGGER.debug("债权查询为空");
            }else{
                LOGGER.debug("查询成功！");
            }
        } catch (Exception e) {
            LOGGER.error("查询异常"+e.getMessage());
        }
        return CreditorList;
    }
}
